﻿/**
 * Copyright (C) 2011 original author and authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NGuice.Inject.Spi
{
    //complete!
    /// <summary>
    /// 绑定目标的访问策略，用于查找适合一个注入的实例
    /// </summary>
    /// <typeparam name="V">访问方法返回的对象，如果没有返回类型，使用Void</typeparam>
    public interface IBindingTargetVisitor<T, V>
    {
        V Visit(IInstanceBinding<T> binding);

        V Visit(IProviderInstanceBinding<T> binding);

        V Visit(IProviderKeyBinding<T> binding);

        V Visit(ILinkedKeyBinding<T> binding);

        V Visit(IExposedBinding<T> binding);

        V Visit(IUntargettedBinding<T> binding);

        V Visit(IConstructorBinding<T> binding);

        V Visit(IConvertedConstantBinding<T> binding);

        V Visit(IProviderBinding binding);
    }


    /// <summary>
    /// 无操作的访问器子类。所有界面方法都简单的代理到<code>visitOther(Binding)</code>返回他们的结果
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <typeparam name="V"></typeparam>
    public abstract class DefaultBindingTargetVisitor<T, V> : IBindingTargetVisitor<T, V>
    {

        protected virtual V VisitOther(IBinding binding)
        {
            return default(V);
        }

        public virtual V Visit(IInstanceBinding<T> binding)
        {
            return VisitOther(binding);
        }

        public virtual V Visit(IProviderInstanceBinding<T> binding)
        {
            return VisitOther(binding);
        }

        public virtual V Visit(IProviderKeyBinding<T> binding)
        {
            return VisitOther(binding);
        }

        public virtual V Visit(ILinkedKeyBinding<T> binding)
        {
            return VisitOther(binding);
        }

        public virtual V Visit(IExposedBinding<T> binding)
        {
            return VisitOther(binding);
        }

        public virtual V Visit(IUntargettedBinding<T> binding)
        {
            return VisitOther(binding);
        }

        public virtual V Visit(IConstructorBinding<T> binding)
        {
            return VisitOther(binding);
        }

        public virtual V Visit(IConvertedConstantBinding<T> binding)
        {
            return VisitOther(binding);
        }

        public virtual V Visit(IProviderBinding binding)
        {
            return VisitOther(binding);
        }
    }
}
